#-*-coding:utf-8-*-
#author:fanerlei
#date:2021.8.20
# https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/
#  二维数组中的查找
# https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/
#  第一个只出现一次的字符


def findNumberIn2DArray( matrix, target):
	if not matrix or not target:
		return False

	n, m = len(matrix), len(matrix[0])
	row, col = 0, m - 1
	# 从右上角开始
	while (row >= 0 and row < n and col >= 0 and col < m):
		if matrix[row][col] > target:
			col -= 1
		elif matrix[row][col] < target:
			row += 1
		else:
			return True

		pass
	return False


def firstUniqChar( s):
	"""
	:type s: str
	:rtype: str
	"""
	if not s:
		return " "
	tmpDict = {}
	for idx, char in enumerate(s):
		if not tmpDict.has_key(char):
			tmpDict[char] = 1
		else:
			tmpDict[char] += 1
	for char in s:
		if tmpDict[char] == 1:
			return char
	return " "

if __name__ == "__main__":
	print findNumberIn2DArray([
							  [1,   4,  7, 11, 15],
							  [2,   5,  8, 12, 19],
							  [3,   6,  9, 16, 22],
							  [10, 13, 14, 17, 24],
							  [18, 21, 23, 26, 30]
							],80)


	print firstUniqChar("fans")

